import { hasOwn } from "@vue/shared";

export const PublicInstanceProxyHandlers = {
  get({_: instatnce}, key) {
    const {setupState, props, data} = instatnce;

    if (key[0] == '$'){
      return; // 不能访问以 $ 开头的变量
    }
    
    if (hasOwn(setupState, key)) {
      return setupState[key];
    } else if (hasOwn(props, key)) {
      return props[key];
    } else if (hasOwn(data, key)) {
      return data[key];
    }
  },
  set({_: instatnce}, key, value) {
    const {setupState, props, data} = instatnce;

    if (hasOwn(setupState, key)) {
      setupState[key] = value;
    } else if (hasOwn(props, key)) {
      props[key] = value;
    } else if (hasOwn(data, key)) {
      data[key] = value;
    }
  }
}